package java复习202407;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Field;
import java.util.List;

public class c15_类型转换验证 {

    class User{
        String name;
        String age;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getAge() {
            return age;
        }

        public void setAge(String age) {
            this.age = age;
        }
    }

    @Test
    public void json转对象(){
        User user = new User();
        user.setAge("11");
        user.setName("张三");

        String userStr = JSON.toJSONString(user);
        System.out.println(userStr);

        System.out.println();

        Object parse = JSON.parse(userStr);
        JSONObject jsonObject = JSON.parseObject(userStr);
        System.out.println("jsonObjest"+jsonObject.containsKey("name"));
        System.out.println(parse);
        System.out.println(parse instanceof User);


        Field[] fields = parse.getClass().getDeclaredFields();
        boolean batchThaw = true;
        for (Field field : fields) {
            if ("name".equals(field.getName())){
                batchThaw = false;
                break;
            }
        }

        System.out.println(batchThaw);

    }


}
